<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"> 频道名称：</label>
                            <div class="col-sm-8">
                                <input maxlength="4" id="catalogname" name="catalogname" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属产品：</label>
                            <div class="col-sm-8">
                                <select onchange="getCataloDistrict()" id="productid" name="productid"
                                        class="form-control" type="text">
                                    <option value="">---请选择---</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">频道类型：</label>
                            <div class="col-sm-8">
                                <select onchange="getDistrict()" id="catalogtype" name="catalogtype"
                                        class="form-control" type="text">
                                    <option value="1">自营</option>
                                    <option value="2">外放</option>
                                    <option value="3">全局</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="aaaaaa">
                            <label class="col-sm-3 control-label">外放链接：</label>
                            <div class="col-sm-8">
                                <input maxlength="1024" id="catalogurl" name="catalogurl" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group" id="bbbbbb">
                            <label class="col-sm-3 control-label">标签管理：</label>
                            <div class="col-sm-8">
                                <select data-live-search="true" multiple="multiple" id="tagid" name="tagid"
                                        class="selectpicker form-control" type="text">
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="cccccc">
                            <label class="col-sm-3 control-label">频道模版：</label>
                            <div class="col-sm-8">
                                <select id="catalogtemplate" name="catalogtemplate"
                                        class="form-control" type="text">
                                    <option value="">---请选择---</option>
                                    <option value="1">模板1</option>
                                    <option value="2">模板2</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">优先级：</label>
                            <div class="col-sm-8">
                                <input onkeyup="this.value=this.value.replace(/\D/g,'')"
                                       onafterpaste="this.value=this.value.replace(/\D/g,'')" maxlength="4"
                                       id="catalogsort"
                                       name="catalogsort" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">描述：</label>
                            <div class="col-sm-8">
                                <input maxlength="1024" id="catalogdes" name="catalogdes" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" src="/js/appjs/market/productCatalog/add.js">
</script>
<script type="text/javascript" src="/js/appjs/bootstrap-select/bootstrap-select.js">
</script>
<link rel="stylesheet" href="/js/appjs/bootstrap-select/bootstrap-select.min.css"/>
<script type="text/javascript" th:inline="javascript">
    $(window).on('load', function () {
        $('.selectpicker').selectpicker('val', '');
        $('.selectpicker').selectpicker('refresh');
    });

    function getDistrict() {
        $("#catalogurl").val('');
        $("#catalogtemplate").val('');
        $("#tagid").val('');
        var catalogtype = $("#catalogtype").val();
        if (catalogtype == 2) {
            $("#aaaaaa").show();
            $("#bbbbbb").hide();
            $("#cccccc").hide();
        } else if (catalogtype == 1) {
            $("#aaaaaa").hide();
            $("#bbbbbb").show();
            $("#cccccc").show();
        } else {
            $("#aaaaaa").hide();
            $("#bbbbbb").hide();
            $("#cccccc").hide();
        }
    }

    function getCataloDistrict() {
        var productid = $("#productid").val();
        $.ajax({
            type: 'get',
            url: '/market/productCatalog/listAllTags',
            dataType: 'json',
            data: {
                productId: productid,
            },
            success: function (datas) {
                //返回list数据并循环获取
                var select = $("#tagid");
                for (var i = 0; i < datas.length; i++) {
                    select.append("<option value='" + datas[i].tagId + "'>"
                        + datas[i].tagName + "</option>");
                }
                $('.selectpicker').selectpicker('val', '');
                $('.selectpicker').selectpicker('refresh');
            }
        });
    }

    $(function () {
        $(".selectpicker").selectpicker({
            noneSelectedText: '请选择'//默认显示内容
        });
        getDistrict();
        $.ajax({
            type: 'get',
            url: '/market/productChannel/listAllProduct?channelid=' + $("#channelid").val(),
            dataType: 'json',
            success: function (datas) {
                //返回list数据并循环获取
                var select = $("#productid");
                for (var i = 0; i < datas.length; i++) {
                    select.append("<option value='" + datas[i].id + "'>"
                        + datas[i].productName + "</option>");
                }
            }
        });
    })


</script>
</body>
</html>
